/*
* Copyright (c) 2016 ShopJsp. All Rights Reserved.
 * ============================================================================
 * 版权所有 2011 - 今 北京华宇盈通科技有限公司，并保留所有权利。
 * ----------------------------------------------------------------------------
 * 提示：在未取得SHOPJSP商业授权之前，您不能将本软件应用于商业用途，否则SHOPJSP将保留追究的权力。
 * ----------------------------------------------------------------------------
 * 官方网站：http://www.shopjsp.com
 * ============================================================================
*/
package com.hyyt.shopjsp.util.cookie;

import com.hyyt.shopjsp.util.common.StringStaticKey;
import com.hyyt.shopjsp.util.common.Utils;
import com.hyyt.shopjsp.util.number.SerialNumberUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Cookie 操作凭证类
 *
 * @author: ankang
 * @Date 2016/7/27 0027 上午 11:42
 */
public class CookieEvidence {

    /**
     * 生成购物车验证凭证
     *
     * @param request
     * @param response
     * @return 凭证码
     */
    public static String generateCartEvidence(HttpServletRequest request, HttpServletResponse response) {
        String evidence = CookieUtil.getCookieValue(request, StringStaticKey.COOKIE_CART_USER_KEY);//获取
        if (!Utils.stringIsNotEmpty(evidence)) {
            String uuid ="cart_"+SerialNumberUtil.uuidGenerate();//生成UUID唯一标识
            CookieUtil.setCookie(request, response, StringStaticKey.COOKIE_CART_USER_KEY, uuid);
            evidence = uuid;
        }
        return evidence;
    }
    /**
     * 生成购物车数量的验证凭证
     * @param request
     * @param response
     * @return 凭证码
     */
    public static String generateCartCountEvidence(HttpServletRequest request, HttpServletResponse response) {
        String evidence = CookieUtil.getCookieValue(request, StringStaticKey.COOKIE_CARTCOUNT_USER_KEY);//获取
        if (!Utils.stringIsNotEmpty(evidence)) {
            String uuid ="cartCount_"+SerialNumberUtil.uuidGenerate();//生成UUID唯一标识
            CookieUtil.setCookie(request, response, StringStaticKey.COOKIE_CARTCOUNT_USER_KEY, uuid);
            evidence = uuid;
        }
        return evidence;
    }

}
